package movie.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import movie.entity.Cinema;
import movie.entity.Film;
import movie.entity.FilmDate;
import movie.mapper.CinemaMapper;
import movie.service.CinemaScheduleFindAllService;

@Service
public class CinemaScheduleFindAllServiceImpl implements CinemaScheduleFindAllService {

	@Autowired
	private CinemaMapper cinemaMapper;
	
	@Override
	public List<Cinema> findAll() {
		// TODO Auto-generated method stub
		return cinemaMapper.findAll();
	}
	
	@Override
	public List<Cinema> find(int movieId) {
		// TODO Auto-generated method stub
		return cinemaMapper.findByMovieId(movieId);
	}
	@Override
	public List<Cinema> Userfind(int movieId) {
		// TODO Auto-generated method stub
		return cinemaMapper.findMovieID(movieId);
	}
	@Override
	public Cinema findByScheduleId(int scheduleId) {
		// TODO Auto-generated method stub
		Cinema cinema= cinemaMapper.findByScheduleId(scheduleId);
		Date d1=cinema.getFilmBeginTime();
		Calendar cal = Calendar.getInstance();
		cal.setTime(d1);
		int month = cal.get(Calendar.MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		String filmTime=month+"月"+day+"日";
		cinema.setFilmTime(filmTime);
		return cinema;
	}
	
	@Override
	public int  update(Cinema cinema) {
		// TODO Auto-generated method stub
		return cinemaMapper.update(cinema);
	}
	
	@Override
	public List<Cinema> findByMovieIdCinemaId(Cinema cinema) {
		// TODO Auto-generated method stub
		return cinemaMapper.findByMovieIdCinemaId(cinema);
	}
	
	@Override

	public List<Film>  findAllFilm(int cinemaId) {
		// TODO Auto-generated method stub
		return cinemaMapper.findAllFilm(cinemaId);
	}
	@Override
	public List<FilmDate> findAllSchedule(Cinema cinema) {
		// TODO Auto-generated method stub
		List<FilmDate> filmDate= cinemaMapper.findSchedule(cinema);
		for(FilmDate fd:filmDate) {
			Date d1=fd.getTime();
			Calendar cal = Calendar.getInstance();
    		cal.setTime(d1);
    		int month = cal.get(Calendar.MONTH);
    		int day = cal.get(Calendar.DAY_OF_MONTH);
    		String filmTime=month+"月"+day+"日";
			fd.setFilmTime(filmTime);
		}
		return filmDate;
	}
	public List<Cinema> findByMovieIdCinemaIdHallName(Cinema cinema)
	{
		return cinemaMapper.findByMovieIdCinemaIdHallName(cinema);
	}
	
	@Override
	public List<Cinema> findByMovieIdDateCinemaId(Cinema cinema)
	{
		return cinemaMapper.findByMovieIdDateCinemaId(cinema);
	}
}
